﻿using Abp.Runtime.Caching;
using Mt.Site.Core.Common.Cache;
using Mt.Site.Core.Organizations.UserCache.Models;
using System.Collections.Generic;

namespace Mt.Site.Core.WorkFlows.Common.Cache
{
    public static class UserInfoCacheExtensions
    {
        public const string UserInfoCacheStoreName = "AppUserInfoCache";
        public const string AllUsersCacheStoreName = "AppAllUsersCache";
        public const string AllUserOrganinzedCacheName = "AppAllUserOrganinzedCache";
        public const string AllUnitsCacheStoreName = "AppAllUnitsCache";
        public const string AllPostsCacheStoreName = "AppAllPostsCache";

        // 用户 id 查用户信息， 不适用批量查找
        public static ITypedCache<string, UserInfoCacheItem> GetUserInfoCache(this ICacheManager cacheManager)
        {
            return cacheManager.GetCache<string, UserInfoCacheItem>(UserInfoCacheStoreName);
        }


        public static string GetCommonCacheKey(this ICacheManager cacheManager, int? tenantId)
        {
               return "0@" + tenantId;
        }
        public static ITypedCache<string, List<UserListCacheItem>> GetAllUsersCache(this ICacheManager cacheManager)
        {
            return cacheManager.GetCache<string, List<UserListCacheItem>>(AllUsersCacheStoreName);
        }
        public static ITypedCache<string, List<UserOrganinzedCacheItem>> GetAllUserOrganinzedCache(this ICacheManager cacheManager)
        {
            return cacheManager.GetCache<string, List<UserOrganinzedCacheItem>>(AllUserOrganinzedCacheName);
        }

        public static ITypedCache<string, List<UnitSelectionData>> GetAllUnitsCache(this ICacheManager cacheManager)
        {
            return cacheManager.GetCache<string, List<UnitSelectionData>>(AllUnitsCacheStoreName);
        }

        public static ITypedCache<string, List<PostItemData>> GetAllPostsCache(this ICacheManager cacheManager)
        {
            return cacheManager.GetCache<string, List<PostItemData>>(AllPostsCacheStoreName);
        }

        // TODO: 完善 全体用户和部门的关系缓存、部门数据的缓存,职务的缓存 , UserInfoCacheItem的缓存 应该从前面的缓存中获取数据

        /*
         *  1. 所有已发布部门的数据
         *  2. 所有用户及他们与部门的关系数据 所有有部门的用户 及 每个用户关联的所有部门
         *  3. 每个用户的详细数据
         * 
         * 
         * UserRoleUnitSelectionAppService,
         *         GetOrganizationUnitsAsync  改调用部门缓存             ok
         *         GetAllLv1UnitsAsync        改调用部门缓存             ok
         *         GetUserOrganinzationAsync  改调用用户部门缓存（需加载所有用户）   ok
         *         
         * UserAndUnitFinder
         *         GetUserIdListByUnitId      改调用用户部门缓存
         *         GetAllUnitSelectionData    改调用部门缓存             ok
         *         GetUserItemList            改调用用户部门缓存         ok
         *         GetUnitsWithTheirParents(List<long> UserIdList)                      改调用用户部门缓存 及 部门缓存     ok
         *         GetUnitsWithTheirParents(IEnumerable<UnitSelectionData> unitUnits)   改调用部门缓存                     ok
         *         GetAllPostAsync            改用职务缓存               ok
         *         
         * WorkFlowDesignAppService.GetFilterUnitsAsync     改调用部门缓存  ok
         * 
         */
    }
}
